package com.yy.listener;

import com.rabbitmq.client.Channel;
import com.yy.po.Order;
import com.yy.po.OrderDetail;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class MyOrderListener {

    @RabbitListener(queues = "q.order", ackMode = "MANUAL")
    public void onMessage(Order order, Channel channel, Message message) throws Exception {
        System.out.println(order.getOrderId() + "\t" + order.getUserId() + "\t" + order.getStatus());
        for (OrderDetail detail : order.getDetails()) {
            System.out.println(
                    detail.getItemId() + "\t"
                            + detail.getItemName() + "\t"
                            + detail.getItemPrice() + "\t"
                            + detail.getNum()
            );
        }
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
